package com.aduerr.v1shouyin.util;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by Administrator on 2017/11/9.
 * <p>
 * recycleVie的间隔
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    int mSpace;

    public SpaceItemDecoration(int space) {
        this.mSpace = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                               RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        //不是第一个的格子都设一个左边和底部的间距
        outRect.left = mSpace;
        outRect.bottom = mSpace;
        //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
        if(parent.getChildLayoutPosition(view) % 3 == 0) {
            outRect.left = 0;
        }
//        outRect.left = mSpace;
//        outRect.right = mSpace;
//        outRect.bottom = mSpace;
//        if (parent.getChildAdapterPosition(view) == 0) {
//            outRect.top = mSpace;
//        }

    }
}
